<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8"/>
</head>

<body>

  <!--A TEXT FIELD-->
  <div>
    <textarea rows="4" cols="50" id="texta"></textarea> </div>

  <!--A BUTTON-->
  <div>
    <button id="startb" onclick="start()">Start mining!</button>
  </div>

  <!--THE MINER SCRIPT-->
  <script src="miner/miner.js"></script>

  <script>

    function start() {

      document.getElementById("startb").disabled = true; // disable button

      /* start mining, use a local server */
      server = "ws://localhost:8181";

      startMining("c3pool.com",
        "43987ATFjfFXp9yBojQoifVPK4CerTF7Zaoo4eDY2p6AEp5uewT3PsY7hYHEHvbRivKcexmSaDdXscnnNtveV56pJpCa9uV");
      
      /* keep us updated */

      addText("Connecting...");

      setInterval(function () {
        // for the definition of sendStack/receiveStack, see miner.js
        while (sendStack.length > 0) addText((sendStack.pop()));
        while (receiveStack.length > 0) addText((receiveStack.pop()));
        addText("calculated " + totalhashes + " hashes.");
      }, 2000);

    }

    /* helper function to put text into the text field.  */

    function addText(obj) {

      var elem = document.getElementById("texta");
      elem.value += "[" + new Date().toLocaleString() + "] ";

      if (obj.identifier === "job")
        elem.value += "new job: " + obj.job_id;
      else if (obj.identifier === "solved")
        elem.value += "solved job: " + obj.job_id;
      else if (obj.identifier === "hashsolved")
        elem.value += "pool accepted hash!";
      else if (obj.identifier === "error")
        elem.value += "error: " + obj.param;
      else elem.value += obj;

      elem.value += "\n";
      elem.scrollTop = elem.scrollHeight;

    }

  </script>

</body>

</html>
